<?
require("header.php");
?>
<script type="text/javascript" src="../webkit/utils/jquery.js"></script>
<link href="css/home.css" type="text/css" rel="stylesheet" />
<style>
	.login_text { width:230px; height:26px; border:#99cc33 1px solid; font-size:18px; font-family:arial; color:#ff3300}
</style>
</head>
<body style="margin:0px;background:white;" onload="$('#mobile').focus()">
	<? require("top.php"); ?>
	<div style="width:100%;background:#efefef;border-top:#ddd 5px solid; border-bottom:#ddd 5px solid">
		<div style="width:900px; height:430px; text-align:center; background:white; margin:auto">
			<br><br>
			<table align=center style="color:green; font-size:18px; font-weight:bold; border:dashed 5px #efefef" width="550" cellpadding=8>
			<tr><td colspan=2 style="background:#f4f4f4; border-bottom:#efefef 2px solid; font-size:20px; color:#666" align=left>顾客登录</td></tr>
			<tr><td width=20%  align="right">手机号</td><td width=80% align=left><input type="text" id="mobile" class="login_text" onkeyup="check_mobile(this.value)"><span id="mobile_tips"></span></td></tr>
			<tr><td align="right">密　码</td><td align=left><input type="password" id="login_pass" class="login_text" onkeyup="if(event.keyCode == 13) {do_login()}"></td></tr>
			<tr><td align="right"></td><td align=left>
			<span id="btn_login"><img src="images/login_button.jpg" style="cursor:hand" onclick="do_login()"></span><span style="color:green;display:none" id="post_waiting"><img src="images/loading.gif" style="vertical-align:middle"> 正在验证中，请稍候...</span>
			</td></tr>
			<tr style="font-size:13px; color:gray"><td align="right">【说明】
</td><td align=left style="font-weight:normal">
			<li> 您在首次提交定单后，系统会以手机号进行自动注册；
			<li> 会员成功注册后，系统会发送一条初始密码通知短信；
			<li> 如果您忘记密码，请点击按钮短信找回 <input type="button" id="btn_send_pwd" value="发送密码" onclick="send_password()">
			</td></tr>
			</table>
		</div>
	</div>
	<script>
	    var mobile_is_ok = false;

		function check_mobile(v) {
			$.get("user_query.php?action=check_mobile&mobile="+v, function(data){
				if(data == "yes") {
					mobile_is_ok = true
					$("#mobile_tips").html("<img src='images/check_ok.jpg' width=25>");
				} else {
					mobile_is_ok = false;
					$("#mobile_tips").html("&nbsp;<font color=red style='font-size:13px'>*无此账号</font>");
				}
			});
		}

	    
		<?if( empty($_GET['to_url']) ) {?>
			var to_url = "./main.php";
		<?} else {?>
			var to_url = "<?echo $_GET['to_url']?>";
		<?}?>

		function do_login() {
			var m = $("#mobile").val();
			var p = $("#login_pass").val();
			if(m=="" || p=="") {
				alert("请输入您的手机号及账户密码！");
				return false;
			}
			$("#btn_login").hide();
			$("#post_waiting").show();
			$.get("user_query.php?action=check_user&mobile="+m+"&login_pass="+p, function(data){
				if(data == "yes") {
					window.location = to_url;
				} else {
					alert("用户登录验证失败，请重试！");
					$("#btn_login").show();
					$("#post_waiting").hide();
				}
			});
		}

		var wait_timer = null;
		function send_password() {
			var m = $("#mobile").val();
			if(m=="") {
				alert("请输入您的手机号，以便接收我们的密码短信通知！");
				return false;
			}
			if( ! mobile_is_ok ) {
				alert("您输入的手机号码不存在，请确认后重试！");
				return false;	
			}
			if(confirm("确认要通过手机号["+m+"]找回密码吗？")) {
				$.get("user_query.php?action=send_password&mobile="+m, function(data){
					if(data == "ok") {
						alert("账户密码已通过短信发送至您的手机["+m+"]，请注意查收！");
						$("#btn_send_pwd").val("60秒后重发");
						$("#btn_send_pwd").attr("disabled", true);
						wait_timer = setInterval("run_wait_timer()", 1000);

					} else if(data == "no_user"){
						alert("对不起，您的手机号码尚未在本站注册！");
					} else {
						alert("操作失败，请重试！");
					}
				});
			}
		}

		var run_index = 60;
		function run_wait_timer() {
			run_index--;
			if(run_index == 0) {
				clearInterval(wait_timer);
				$("#btn_send_pwd").val("发送密码");
				$("#btn_send_pwd").attr("disabled", false);
				run_index = 60;
			} else {
				$("#btn_send_pwd").val(run_index+"秒后重发");
			}
		}
	</script>
	<? require("bottom.php"); ?>

</body>
</html>